/**
 * Created by Administrator on 2016/8/3 0003.
 */
import React from 'react';

var scope;
export default class GoodsDisCounter extends React.Component{
    constructor(props){
        super(props);
        scope = this;
    };

    handleDisPlusNumber(){
        var max = scope.props.max;
        var num = scope.props.data;
        if(max){
            if(max < (num + 1)){
                return;
            }
        }
        scope.props.disNumberCallback(num + 1);
    };

    handleDisMinusNumber(){
        var min = scope.props.min;
        var num = scope.props.data;
        if(min < num){
            scope.props.disNumberCallback(num - 1);

        }else {
            return;
        }
    };


    render(){
        return (
            <div className="choose-box number-box">
                <div className="choose-box-left">购买数量：</div>
                <div className="choose-box-right">
                    {this.numberItems()}
                </div>
            </div>
        );
    };

    numberItems(){
        var num = scope.props.data;
        var max = scope.props.max;
        var min = scope.props.min;
        var minGrayClass = '';
        var maxGrayClass = '';
        if(max && max == num){
            maxGrayClass = 'gray-counter';
        }
        if(min == num){
            minGrayClass = 'gray-counter';
        }
        return (
            <ul className="counter">
                <li className={minGrayClass} onClick={this.handleDisMinusNumber}> - </li>
                <li> {scope.props.data} </li>
                <li className={maxGrayClass} onClick={this.handleDisPlusNumber}> + </li>
            </ul>
        );
    };
};
